from django.contrib.auth.models import User
from django.db import models

# Create your models here.

"""
auto_now_add:创建models对象的时间设置为默认值，设置好之后不能更改
auto_now:创建/更新models对象的时候，更新时间为当前时间,他会随着models的更新不断变化的
"""


# 博客文章 model
class Article(models.Model):
    # 标题
    title = models.CharField(verbose_name="标题", max_length=100)
    # 正文
    body = models.TextField("正文")
    # 创建时间
    created = models.DateTimeField(auto_now_add=True)
    # 更新时间
    updated = models.DateTimeField(auto_now=True)

    author = models.ForeignKey(
        User,
        null=True,
        on_delete=models.CASCADE,
        related_name='articles'
    )

    def __str__(self):
        return self.title